package com.situ.crm.controller;

import javax.swing.plaf.synth.SynthStyle;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.Product;
import com.situ.crm.service.IProductService;

@Controller
@RequestMapping(value="/product")
public class ProductController {
	@Autowired
	private IProductService productService;
	
	@RequestMapping(value="/getProductPage")
	public String getProductPage() {
		return "product/product_list";
	}
	
	//分页
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Product product) {
		ServerResponse serverResponse = productService.pageList(page,limit,product);
		return serverResponse;
	}
	
	//添加页面
	@RequestMapping(value="/getAddPage")
	public String getAddPage() {
		return "product/product_insert";
	}
	
	//添加功能
	@RequestMapping(value="/insert")
	@ResponseBody
	public ServerResponse insert(Product product) {
		return productService.insert(product);
	}
	
	//删除功能
	@RequestMapping(value="/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return productService.deleteById(id);
	}
	
	//批量删除
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return productService.deleteAll(ids);
	}
	
	//修改页面
    @RequestMapping(value="getUpdatePage")
	public String getUpdatePage(Integer id,Model model) {
    	Product product = productService.select(id);
    	model.addAttribute("product",product);
		return "product/product_update";
	}
    
    //修改
    @RequestMapping(value="/update")
    @ResponseBody
    public ServerResponse update(Product product) {
    	System.err.println(product);
		return productService.update(product);
	}
    
    /*ECharts统计商品数量*/
    @RequestMapping(value="/getProductCountPage")
    public String getProductCountPage() {
		return "product/product_count";
	}
    
    @RequestMapping(value="/productCount")
    @ResponseBody
    public ServerResponse productCount() {
		return productService.selectProductCount();
	}
    
}
